package top.itaso.app.ui.treelevel;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import java.util.ArrayList;

import top.itaso.app.databinding.FragmentExpandablelistviewBinding;
import top.itaso.app.ui.treelevel.adapter.ExpandableListViewAdapter;
import top.itaso.lib.widget.vo.Node;

/**
 * @Description: ExpandableListView 二级列表
 * @Author itsdf07
 * @E-Mail 923255742@qq.com
 * @Gitee https://gitee.com/itsdf07
 * @Date 2021/12/5
 */
public class ExpandableListViewFragment extends Fragment {
    private MultiLevelListViewModel mViewModel;
    private FragmentExpandablelistviewBinding binding;

    private ExpandableListView mMultiLevelList;
    private ExpandableListViewAdapter mAdapter;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        binding = FragmentExpandablelistviewBinding.inflate(inflater, container, false);
        View rootView = binding.getRoot();
        mAdapter = new ExpandableListViewAdapter();
        mMultiLevelList = binding.multilevelExpandable;
        mMultiLevelList.setAdapter(mAdapter);

        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(MultiLevelListViewModel.class);
        mAdapter.refreshData(mViewModel.simulationNodesExpandable());
        mViewModel.nodes.observe(getViewLifecycleOwner(), new Observer<ArrayList<Node>>() {
            @Override
            public void onChanged(ArrayList<Node> nodes) {
            }
        });

    }
}
